package com.ysyx.ysyx_roborder.mqlisten;

import com.alibaba.fastjson.JSON;
import com.ysyx.ysyx_roborder.pojo.OrderPojo;
import com.ysyx.ysyx_roborder.qo.TakeOrderQo;
import com.ysyx.ysyx_roborder.service.OrderPojoService;
import org.apache.logging.log4j.message.Message;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 *
 * @description: xxxx接口/类
 * @author:薛宇晖
 * @create:2023/4/11 19:47
 */
@Component
@RocketMQMessageListener(topic="order",consumerGroup = "consumerGroup",selectorExpression = "gainset")
public class GainsetOrderListener implements RocketMQListener<MessageExt>, RocketMQPushConsumerLifecycleListener {

    @Autowired
    private OrderPojoService orderPojoService;

    @Override
    public void onMessage(MessageExt messageExt) {
        System.err.println("Received:"+new String(messageExt.getBody()));
        TakeOrderQo o = JSON.parseObject(messageExt.getBody(), TakeOrderQo.class);
        OrderPojo orderPojo = new OrderPojo();
        orderPojo.setOrderId(o.getOrderId());
        orderPojo.setOrderStatus(o.getOrderStatus());
        orderPojo.setDriverId(o.getDriverId());
        orderPojo.setPassengerId(o.getPassengerId());
        orderPojo.setOrderCost(o.getOrderCost());
        orderPojo.setOrderMileage(o.getOrderMileage());
        orderPojo.setEndName(o.getEndName());
        orderPojo.setStartName(o.getStartName());
        orderPojo.setOrderStatustime(o.getOrderStatustime());

//        OrderPojo orderPojo = JSON.parseObject(messageExt.getBody(), OrderPojo.class);
        orderPojoService.updateOrderStatus(orderPojo);


    }

    @Override
    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {

    }
}
